SET client_encoding = 'UTF8';
SET check_function_bodies = false;
SET client_min_messages = warning;

--
-- TOC entry 1829 (class 0 OID 0)
-- Dependencies: 2
-- Name: SCHEMA public; Type: COMMENT; Schema: -; Owner: explica
--

COMMENT ON SCHEMA public IS 'Standard public schema';


--
-- TOC entry 352 (class 2612 OID 41533)
-- Name: plpgsql; Type: PROCEDURAL LANGUAGE; Schema: -; Owner: 
--

CREATE PROCEDURAL LANGUAGE plpgsql;


SET search_path = public, pg_catalog;

--
-- TOC entry 17 (class 1255 OID 41539)
-- Dependencies: 2 352
-- Name: DELETE_EXT_FIELD_VALUES(numeric, character varying); Type: FUNCTION; Schema: public; Owner: explica
--

CREATE FUNCTION "DELETE_EXT_FIELD_VALUES"(numeric, character varying) RETURNS integer
    AS $_$

  DECLARE ID_ITEM ALIAS FOR $1;
  DECLARE COD_EXT_TABLE ALIAS FOR $2;


  DECLARE v_qry VARCHAR(2000) := ' ';
          v_cont INTEGER := 0;
	  v_tmp INTEGER;

  BEGIN
	-- Build the delete query for values of string type extension fields
        v_qry := 'DELETE FROM "ExtFieldStringValue" WHERE "idValue"= ' || ID_ITEM || ' AND "idExtField" IN ' || 
		'(SELECT "idExtField" FROM "ExtFieldDefinition" f, "ExtTableDefinition" t WHERE t."idExtTable" = f."idExtTable" ' ||
		'AND t."codExtTable" = ' || quote_literal(COD_EXT_TABLE) || ');';

	-- Run the delete query for values of string type extension fields
	EXECUTE v_qry;

	-- Get the number of rows affected by the delete query
	GET DIAGNOSTICS v_tmp = ROW_COUNT;

	-- Add the number of affected rows to the total sum
	v_cont := v_cont + v_tmp;

	-- Build the delete query for values of numeric type extension fields
        v_qry := 'DELETE FROM "ExtFieldNumberValue" WHERE "idValue"= ' || ID_ITEM || ' AND "idExtField" IN ' || 
		'(SELECT "idExtField" FROM "ExtFieldDefinition" f, "ExtTableDefinition" t WHERE t."idExtTable" = f."idExtTable" ' ||
		'AND t."codExtTable" = ' || quote_literal(COD_EXT_TABLE) || ');';

	-- Run the delete query for values of numeric type extension fields
	EXECUTE v_qry;

	-- Get the number of rows affected by the delete query
	GET DIAGNOSTICS v_tmp = ROW_COUNT;

	-- Add the number of affected rows to the total sum
	v_cont := v_cont + v_tmp;

	-- Build the delete query for values of date type extension fields
        v_qry := 'DELETE FROM "ExtFieldDateValue" WHERE "idValue"= ' || ID_ITEM || ' AND "idExtField" IN ' || 
		'(SELECT "idExtField" FROM "ExtFieldDefinition" f, "ExtTableDefinition" t WHERE t."idExtTable" = f."idExtTable" ' ||
		'AND t."codExtTable" = ' || quote_literal(COD_EXT_TABLE) || ');';

	-- Run the delete query for values of date type extension fields
	EXECUTE v_qry;

	-- Get the number of rows affected by the delete query
	GET DIAGNOSTICS v_tmp = ROW_COUNT;

	-- Add the number of affected rows to the total sum
	v_cont := v_cont + v_tmp;

	-- Build the delete query for values of boolean type extension fields
        v_qry := 'DELETE FROM "ExtFieldBooleanValue" WHERE "idValue"= ' || ID_ITEM || ' AND "idExtField" IN ' || 
		'(SELECT "idExtField" FROM "ExtFieldDefinition" f, "ExtTableDefinition" t WHERE t."idExtTable" = f."idExtTable" ' ||
		'AND t."codExtTable" = ' || quote_literal(COD_EXT_TABLE) || ');';

	-- Run the delete query for values of boolean type extension fields
	EXECUTE v_qry;

	-- Get the number of rows affected by the delete query
	GET DIAGNOSTICS v_tmp = ROW_COUNT;

	-- Add the number of affected rows to the total sum
	v_cont := v_cont + v_tmp;

	-- Build the delete query for values of long type extension fields
        v_qry := 'DELETE FROM "ExtFieldLongValue" WHERE "idValue"= ' || ID_ITEM || ' AND "idExtField" IN ' || 
		'(SELECT "idExtField" FROM "ExtFieldDefinition" f, "ExtTableDefinition" t WHERE t."idExtTable" = f."idExtTable" ' ||
		'AND t."codExtTable" = ' || quote_literal(COD_EXT_TABLE) || ');';

	-- Run the delete query for values of long type extension fields
	EXECUTE v_qry;

	-- Get the number of rows affected by the delete query
	GET DIAGNOSTICS v_tmp = ROW_COUNT;

	-- Add the number of affected rows to the total sum
	v_cont := v_cont + v_tmp;


        RETURN v_cont;

  END;
  $_$
    LANGUAGE plpgsql;


ALTER FUNCTION public."DELETE_EXT_FIELD_VALUES"(numeric, character varying) OWNER TO explica;

--
-- TOC entry 1831 (class 0 OID 0)
-- Dependencies: 17
-- Name: FUNCTION "DELETE_EXT_FIELD_VALUES"(numeric, character varying); Type: COMMENT; Schema: public; Owner: explica
--

COMMENT ON FUNCTION "DELETE_EXT_FIELD_VALUES"(numeric, character varying) IS '  --
  -- Function: DELETE_EXT_FIELD_VALUES
  --
  -- Action: Delete all the extension values defined for an extended item.
  --
  -- In Parameters: Extended Item id and extension table code.
  --
  -- Out Parameters: None.
  --
  -- Return: NUMBER with the number of registries affected.
  --
  -- Exception: There is no catching mechanism for exceptions so if anyone
  -- is raised, it will be propagated.';


SET default_tablespace = '';

SET default_with_oids = false;

--
-- TOC entry 1319 (class 1259 OID 44773)
-- Dependencies: 1697 1698 1699 2
-- Name: Address; Type: TABLE; Schema: public; Owner: explica; Tablespace: 
--

CREATE TABLE "Address" (
    "idAddress" numeric NOT NULL,
    description character varying NOT NULL,
    address character varying NOT NULL,
    "poBox" character varying,
    "postalCode" character varying NOT NULL,
    city character varying NOT NULL,
    "idCountry" numeric NOT NULL,
    "idProvince" numeric NOT NULL,
    "invoicingAddress" boolean DEFAULT false NOT NULL,
    "deliveryAddress" boolean DEFAULT false NOT NULL,
    version bigint DEFAULT 0 NOT NULL
);


ALTER TABLE public."Address" OWNER TO explica;

--
-- TOC entry 1323 (class 1259 OID 44807)
-- Dependencies: 1703 2
-- Name: Agent; Type: TABLE; Schema: public; Owner: explica; Tablespace: 
--

CREATE TABLE "Agent" (
    "idAgent" numeric NOT NULL,
    name character varying NOT NULL,
    surname character varying NOT NULL,
    "idCard" character varying NOT NULL,
    "incomeTax" double precision NOT NULL,
    "comissionPercentage" double precision NOT NULL,
    version bigint DEFAULT 0 NOT NULL,
    "idDepartment" numeric NOT NULL,
    "idAddress" numeric NOT NULL
);


ALTER TABLE public."Agent" OWNER TO explica;

--
-- TOC entry 1305 (class 1259 OID 41651)
-- Dependencies: 2
-- Name: AppArea; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "AppArea" (
    "idArea" character varying(5) NOT NULL,
    description character varying(255) NOT NULL
);


ALTER TABLE public."AppArea" OWNER TO "explica";

--
-- TOC entry 1296 (class 1259 OID 41564)
-- Dependencies: 1684 2
-- Name: AppResource; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "AppResource" (
    "idResource" numeric NOT NULL,
    "codResource" character varying(50) NOT NULL,
    description character varying(100) NOT NULL,
    path character varying(250) NOT NULL,
    version bigint DEFAULT 0,
    "idArea" character varying
);


ALTER TABLE public."AppResource" OWNER TO "explica";

--
-- TOC entry 1316 (class 1259 OID 44749)
-- Dependencies: 1694 2
-- Name: BankAccount; Type: TABLE; Schema: public; Owner: explica; Tablespace: 
--

CREATE TABLE "BankAccount" (
    "idAccount" numeric NOT NULL,
    description character varying NOT NULL,
    "idBank" numeric NOT NULL,
    "idBranch" numeric NOT NULL,
    "accountNumber" character varying NOT NULL,
    "controlNumber" character varying NOT NULL,
    version bigint DEFAULT 0 NOT NULL
);


ALTER TABLE public."BankAccount" OWNER TO explica;

--
-- TOC entry 1300 (class 1259 OID 41630)
-- Dependencies: 1689 2
-- Name: BarcodeType; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "BarcodeType" (
    "idBarcodeType" numeric NOT NULL,
    description character varying NOT NULL,
    version bigint DEFAULT 0
);


ALTER TABLE public."BarcodeType" OWNER TO "explica";

--
-- TOC entry 1325 (class 1259 OID 44849)
-- Dependencies: 1705 1706 2
-- Name: Client; Type: TABLE; Schema: public; Owner: explica; Tablespace: 
--

CREATE TABLE "Client" (
    "idClient" numeric NOT NULL,
    name character varying NOT NULL,
    "brandName" character varying,
    "idNumber" character varying NOT NULL,
    "codeEDI" character varying,
    "mainContact" character varying,
    phone1 character varying,
    phone2 character varying,
    fax character varying,
    email character varying,
    "vatSystem" character varying,
    "applyEquivalenceSurchage" boolean DEFAULT false NOT NULL,
    "invoiceCopies" smallint,
    "maxRisk" double precision,
    "currentRisk" double precision,
    version bigint DEFAULT 0 NOT NULL,
    "idClientGroup" numeric,
    "idAgent" numeric,
    "idPaymentMethod" numeric,
    "idCurrency" numeric,
    "idInvoicingSerie" numeric NOT NULL,
    "idRappelType" numeric
);


ALTER TABLE public."Client" OWNER TO explica;

--
-- TOC entry 1326 (class 1259 OID 44893)
-- Dependencies: 2
-- Name: ClientAddress; Type: TABLE; Schema: public; Owner: explica; Tablespace: 
--

CREATE TABLE "ClientAddress" (
    "idClient" numeric NOT NULL,
    "idAddress" numeric NOT NULL
);


ALTER TABLE public."ClientAddress" OWNER TO explica;

--
-- TOC entry 1327 (class 1259 OID 44910)
-- Dependencies: 2
-- Name: ClientBankAccount; Type: TABLE; Schema: public; Owner: explica; Tablespace: 
--

CREATE TABLE "ClientBankAccount" (
    "idClient" numeric NOT NULL,
    "idBankAccount" numeric NOT NULL
);


ALTER TABLE public."ClientBankAccount" OWNER TO explica;

--
-- TOC entry 1328 (class 1259 OID 44927)
-- Dependencies: 2
-- Name: ClientContact; Type: TABLE; Schema: public; Owner: explica; Tablespace: 
--

CREATE TABLE "ClientContact" (
    "idClient" numeric NOT NULL,
    "idContact" numeric NOT NULL
);


ALTER TABLE public."ClientContact" OWNER TO explica;

--
-- TOC entry 1324 (class 1259 OID 44826)
-- Dependencies: 1704 2
-- Name: ClientGroup; Type: TABLE; Schema: public; Owner: explica; Tablespace: 
--

CREATE TABLE "ClientGroup" (
    "idClientGroup" numeric NOT NULL,
    description character varying NOT NULL,
    version bigint DEFAULT 0 NOT NULL,
    "idRate" numeric
);


ALTER TABLE public."ClientGroup" OWNER TO explica;

--
-- TOC entry 1315 (class 1259 OID 44735)
-- Dependencies: 1693 2
-- Name: Contact; Type: TABLE; Schema: public; Owner: explica; Tablespace: 
--

CREATE TABLE "Contact" (
    "idContact" numeric NOT NULL,
    name character varying NOT NULL,
    "position" character varying,
    phone character varying,
    fax character varying,
    email character varying,
    version bigint DEFAULT 0 NOT NULL
);


ALTER TABLE public."Contact" OWNER TO explica;

--
-- TOC entry 1350 (class 1259 OID 45030)
-- Dependencies: 1711 2
-- Name: Country; Type: TABLE; Schema: public; Owner: explica; Tablespace: 
--

CREATE TABLE "Country" (
    "idCountry" numeric NOT NULL,
    name character varying NOT NULL,
    "idFlag" numeric NOT NULL,
    version bigint DEFAULT 0 NOT NULL
);


ALTER TABLE public."Country" OWNER TO explica;

--
-- TOC entry 1321 (class 1259 OID 44791)
-- Dependencies: 1701 2
-- Name: Currency; Type: TABLE; Schema: public; Owner: explica; Tablespace: 
--

CREATE TABLE "Currency" (
    "idCurrency" numeric NOT NULL,
    description character varying NOT NULL,
    "conversionRate" double precision NOT NULL,
    "lastUpdate" date,
    "codeISO" character varying,
    "idFlag" numeric,
    version bigint DEFAULT 0 NOT NULL
);


ALTER TABLE public."Currency" OWNER TO explica;

--
-- TOC entry 1320 (class 1259 OID 44783)
-- Dependencies: 1700 2
-- Name: Department; Type: TABLE; Schema: public; Owner: explica; Tablespace: 
--

CREATE TABLE "Department" (
    "idDepartment" numeric NOT NULL,
    name character varying NOT NULL,
    version bigint DEFAULT 0 NOT NULL
);


ALTER TABLE public."Department" OWNER TO explica;

--
-- TOC entry 1322 (class 1259 OID 44799)
-- Dependencies: 1702 2
-- Name: Discount; Type: TABLE; Schema: public; Owner: explica; Tablespace: 
--

CREATE TABLE "Discount" (
    "idDiscount" numeric NOT NULL,
    description character varying NOT NULL,
    version bigint DEFAULT 0 NOT NULL,
    "discountPercentage" double precision NOT NULL
);


ALTER TABLE public."Discount" OWNER TO explica;

--
-- TOC entry 1292 (class 1259 OID 33380)
-- Dependencies: 1683 2
-- Name: ExtFieldBooleanValue; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "ExtFieldBooleanValue" (
    "idExtField" numeric NOT NULL,
    "idValue" numeric NOT NULL,
    value boolean,
    version bigint DEFAULT 0
);


ALTER TABLE public."ExtFieldBooleanValue" OWNER TO "explica";

--
-- TOC entry 1291 (class 1259 OID 33373)
-- Dependencies: 1682 2
-- Name: ExtFieldDateValue; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "ExtFieldDateValue" (
    "idExtField" numeric NOT NULL,
    "idValue" numeric NOT NULL,
    value timestamp without time zone,
    version bigint DEFAULT 0
);


ALTER TABLE public."ExtFieldDateValue" OWNER TO "explica";

--
-- TOC entry 1287 (class 1259 OID 33340)
-- Dependencies: 1678 2
-- Name: ExtFieldDefinition; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "ExtFieldDefinition" (
    "idExtField" numeric NOT NULL,
    "idExtTable" numeric NOT NULL,
    "fieldType" numeric NOT NULL,
    "fieldLength" numeric(6,2),
    "fieldDescription" character varying(100),
    nullable boolean,
    historizable boolean,
    "codExtField" character varying(20) NOT NULL,
    version bigint DEFAULT 0
);


ALTER TABLE public."ExtFieldDefinition" OWNER TO "explica";

--
-- TOC entry 1289 (class 1259 OID 33359)
-- Dependencies: 1680 2
-- Name: ExtFieldLongValue; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "ExtFieldLongValue" (
    "idExtField" numeric NOT NULL,
    "idValue" numeric NOT NULL,
    value oid,
    version bigint DEFAULT 0
);


ALTER TABLE public."ExtFieldLongValue" OWNER TO "explica";

--
-- TOC entry 1290 (class 1259 OID 33366)
-- Dependencies: 1681 2
-- Name: ExtFieldNumberValue; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "ExtFieldNumberValue" (
    "idExtField" numeric NOT NULL,
    "idValue" numeric NOT NULL,
    value numeric,
    version bigint DEFAULT 0
);


ALTER TABLE public."ExtFieldNumberValue" OWNER TO "explica";

--
-- TOC entry 1288 (class 1259 OID 33352)
-- Dependencies: 1679 2
-- Name: ExtFieldStringValue; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "ExtFieldStringValue" (
    "idExtField" numeric NOT NULL,
    "idValue" numeric NOT NULL,
    value character varying,
    version bigint DEFAULT 0
);


ALTER TABLE public."ExtFieldStringValue" OWNER TO "explica";

--
-- TOC entry 1286 (class 1259 OID 33333)
-- Dependencies: 1677 2
-- Name: ExtTableDefinition; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "ExtTableDefinition" (
    "idExtTable" numeric NOT NULL,
    "idFieldName" character varying(50) NOT NULL,
    "codExtTable" character varying(20) NOT NULL,
    "tableDescription" character varying(100),
    version bigint DEFAULT 0
);


ALTER TABLE public."ExtTableDefinition" OWNER TO "explica";

--
-- TOC entry 1352 (class 1259 OID 45051)
-- Dependencies: 1713 2
-- Name: Flag; Type: TABLE; Schema: public; Owner: explica; Tablespace: 
--

CREATE TABLE "Flag" (
    "idFlag" numeric NOT NULL,
    description character varying NOT NULL,
    "idResource" numeric NOT NULL,
    version bigint DEFAULT 0 NOT NULL
);


ALTER TABLE public."Flag" OWNER TO explica;

--
-- TOC entry 1307 (class 1259 OID 41685)
-- Dependencies: 1690 2
-- Name: Image; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "Image" (
    "idImage" numeric NOT NULL,
    path character varying NOT NULL,
    version bigint DEFAULT 0
);


ALTER TABLE public."Image" OWNER TO "explica";

--
-- TOC entry 1832 (class 0 OID 0)
-- Dependencies: 1307
-- Name: TABLE "Image"; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE "Image" IS 'Tabla para guardar las imágenes utilizadas en la aplicación, como por ejemplo imágenes de productos, etc.
Almacena la ruta (en el servidor) del fichero de imagen.';


--
-- TOC entry 1318 (class 1259 OID 44765)
-- Dependencies: 1696 2
-- Name: Installment; Type: TABLE; Schema: public; Owner: explica; Tablespace: 
--

CREATE TABLE "Installment" (
    "idInstallment" numeric NOT NULL,
    "numDays" bigint NOT NULL,
    "pendingQuantity" double precision NOT NULL,
    version bigint DEFAULT 0 NOT NULL,
    "idPaymentMethod" numeric NOT NULL
);


ALTER TABLE public."Installment" OWNER TO explica;

--
-- TOC entry 1329 (class 1259 OID 44944)
-- Dependencies: 1707 1708 2
-- Name: InvoicingSerie; Type: TABLE; Schema: public; Owner: explica; Tablespace: 
--

CREATE TABLE "InvoicingSerie" (
    "idSerie" numeric NOT NULL,
    description character varying NOT NULL,
    "incomeTax" double precision NOT NULL,
    "VATExempt" boolean DEFAULT false NOT NULL,
    version bigint DEFAULT 0 NOT NULL
);


ALTER TABLE public."InvoicingSerie" OWNER TO explica;

--
-- TOC entry 1311 (class 1259 OID 43394)
-- Dependencies: 1691 2
-- Name: MeasureUnit; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "MeasureUnit" (
    "idMeasureUnit" numeric NOT NULL,
    description character varying(256) NOT NULL,
    version bigint DEFAULT 0
);


ALTER TABLE public."MeasureUnit" OWNER TO "explica";

--
-- TOC entry 1317 (class 1259 OID 44757)
-- Dependencies: 1695 2
-- Name: PaymentMethod; Type: TABLE; Schema: public; Owner: explica; Tablespace: 
--

CREATE TABLE "PaymentMethod" (
    "idPaymentMethod" numeric NOT NULL,
    description character varying NOT NULL,
    "genReceiptsAs" character varying,
    version bigint DEFAULT 0 NOT NULL,
    "idBankAccount" numeric NOT NULL
);


ALTER TABLE public."PaymentMethod" OWNER TO explica;

--
-- TOC entry 1297 (class 1259 OID 41572)
-- Dependencies: 1685 1686 2
-- Name: Product; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "Product" (
    "idProduct" numeric NOT NULL,
    reference character varying NOT NULL,
    description character varying(256) NOT NULL,
    barcode character varying NOT NULL,
    "idGroup" numeric NOT NULL,
    price numeric(12,2) NOT NULL,
    "idVat" numeric NOT NULL,
    version bigint DEFAULT 0,
    "averageCost" numeric(12,2),
    "allowNoStock" boolean DEFAULT false,
    "idBarcodeType" numeric NOT NULL,
    "trData" bytea
);


ALTER TABLE public."Product" OWNER TO "explica";

--
-- TOC entry 1299 (class 1259 OID 41606)
-- Dependencies: 1688 2
-- Name: ProductGroup; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "ProductGroup" (
    "idGroup" numeric NOT NULL,
    description character varying(256) NOT NULL,
    version bigint DEFAULT 0,
    "idExtTable" numeric
);


ALTER TABLE public."ProductGroup" OWNER TO "explica";

--
-- TOC entry 1308 (class 1259 OID 41700)
-- Dependencies: 2
-- Name: ProductImage; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "ProductImage" (
    "idProduct" numeric NOT NULL,
    "idImage" numeric NOT NULL
);


ALTER TABLE public."ProductImage" OWNER TO "explica";

--
-- TOC entry 1314 (class 1259 OID 44701)
-- Dependencies: 2
-- Name: ProductMeasureUnit; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "ProductMeasureUnit" (
    "idProduct" numeric NOT NULL,
    "idMeasureUnit" numeric NOT NULL
);


ALTER TABLE public."ProductMeasureUnit" OWNER TO "explica";

--
-- TOC entry 1351 (class 1259 OID 45038)
-- Dependencies: 1712 2
-- Name: Province; Type: TABLE; Schema: public; Owner: explica; Tablespace: 
--

CREATE TABLE "Province" (
    "idProvince" numeric NOT NULL,
    name character varying NOT NULL,
    "idCountry" numeric NOT NULL,
    version bigint DEFAULT 0 NOT NULL
);


ALTER TABLE public."Province" OWNER TO explica;

--
-- TOC entry 1331 (class 1259 OID 44974)
-- Dependencies: 1710 2
-- Name: RappelInterval; Type: TABLE; Schema: public; Owner: explica; Tablespace: 
--

CREATE TABLE "RappelInterval" (
    "idRappelInterval" numeric NOT NULL,
    "idRappelType" numeric NOT NULL,
    "inferiorLimit" double precision NOT NULL,
    "superiorLimit" double precision NOT NULL,
    version bigint DEFAULT 0 NOT NULL,
    "discountPercentage" double precision NOT NULL
);


ALTER TABLE public."RappelInterval" OWNER TO explica;

--
-- TOC entry 1330 (class 1259 OID 44966)
-- Dependencies: 1709 2
-- Name: RappelType; Type: TABLE; Schema: public; Owner: explica; Tablespace: 
--

CREATE TABLE "RappelType" (
    "idRappel" numeric NOT NULL,
    description character varying NOT NULL,
    version bigint DEFAULT 0 NOT NULL
);


ALTER TABLE public."RappelType" OWNER TO explica;

--
-- TOC entry 1313 (class 1259 OID 44504)
-- Dependencies: 1692 2
-- Name: Rate; Type: TABLE; Schema: public; Owner: explica; Tablespace: 
--

CREATE TABLE "Rate" (
    "idRate" numeric NOT NULL,
    name character varying NOT NULL,
    "percentIncrease" real,
    "linearIncrease" real,
    version bigint DEFAULT 0 NOT NULL
);


ALTER TABLE public."Rate" OWNER TO explica;

--
-- TOC entry 1306 (class 1259 OID 41669)
-- Dependencies: 1419 2
-- Name: VW_APP_AREAS; Type: VIEW; Schema: public; Owner: explica
--

CREATE VIEW "VW_APP_AREAS" AS
    SELECT a."idArea", a.description AS "areaDescripction", r."idResource" AS "idModule", r."codResource" AS "codModule", r.description AS "moduleDescription", r.path AS "modulePath", r.version AS "moduleVersion" FROM "AppArea" a, "AppResource" r WHERE ((a."idArea")::text = (r."idArea")::text) ORDER BY a."idArea", r."idResource";


ALTER TABLE public."VW_APP_AREAS" OWNER TO explica;

--
-- TOC entry 1310 (class 1259 OID 43307)
-- Dependencies: 1420 2
-- Name: VW_EXT_FIELDS; Type: VIEW; Schema: public; Owner: admin
--

CREATE VIEW "VW_EXT_FIELDS" AS
    SELECT t."idExtTable", t."codExtTable", t."idFieldName", t."tableDescription", f."idExtField", f."codExtField", f."fieldType", f."fieldLength", f."fieldDescription", f.nullable, f.historizable FROM "ExtTableDefinition" t, "ExtFieldDefinition" f WHERE (t."idExtTable" = f."idExtTable") ORDER BY t."idExtTable", f."idExtField";


ALTER TABLE public."VW_EXT_FIELDS" OWNER TO "explica";

--
-- TOC entry 1295 (class 1259 OID 41487)
-- Dependencies: 1418 2
-- Name: VW_EXT_ITEM_VALUES; Type: VIEW; Schema: public; Owner: admin
--

CREATE VIEW "VW_EXT_ITEM_VALUES" AS
    ((((SELECT DISTINCT t."idExtTable", t."codExtTable", t."idFieldName", t."tableDescription", f."idExtField", f."codExtField", f."fieldType", f."fieldLength", f."fieldDescription", f.nullable, f.historizable, v."idValue", v.value AS "strVal", NULL::numeric AS "numVal", NULL::timestamp with time zone AS "datVal", NULL::boolean AS "booVal", NULL::oid AS "lonVal" FROM "ExtTableDefinition" t, "ExtFieldDefinition" f, "ExtFieldStringValue" v WHERE ((t."idExtTable" = f."idExtTable") AND (f."idExtField" = v."idExtField")) ORDER BY t."idExtTable", t."codExtTable", t."idFieldName", t."tableDescription", f."idExtField", f."codExtField", f."fieldType", f."fieldLength", f."fieldDescription", f.nullable, f.historizable, v."idValue", v.value, 14, 15, 16, 17) UNION (SELECT DISTINCT t."idExtTable", t."codExtTable", t."idFieldName", t."tableDescription", f."idExtField", f."codExtField", f."fieldType", f."fieldLength", f."fieldDescription", f.nullable, f.historizable, v."idValue", NULL::text AS "strVal", v.value AS "numVal", NULL::timestamp with time zone AS "datVal", NULL::boolean AS "booVal", NULL::oid AS "lonVal" FROM "ExtTableDefinition" t, "ExtFieldDefinition" f, "ExtFieldNumberValue" v WHERE ((t."idExtTable" = f."idExtTable") AND (f."idExtField" = v."idExtField")) ORDER BY t."idExtTable", t."codExtTable", t."idFieldName", t."tableDescription", f."idExtField", f."codExtField", f."fieldType", f."fieldLength", f."fieldDescription", f.nullable, f.historizable, v."idValue", 13, v.value, 15, 16, 17)) UNION (SELECT DISTINCT t."idExtTable", t."codExtTable", t."idFieldName", t."tableDescription", f."idExtField", f."codExtField", f."fieldType", f."fieldLength", f."fieldDescription", f.nullable, f.historizable, v."idValue", NULL::text AS "strVal", NULL::numeric AS "numVal", v.value AS "datVal", NULL::boolean AS "booVal", NULL::oid AS "lonVal" FROM "ExtTableDefinition" t, "ExtFieldDefinition" f, "ExtFieldDateValue" v WHERE ((t."idExtTable" = f."idExtTable") AND (f."idExtField" = v."idExtField")) ORDER BY t."idExtTable", t."codExtTable", t."idFieldName", t."tableDescription", f."idExtField", f."codExtField", f."fieldType", f."fieldLength", f."fieldDescription", f.nullable, f.historizable, v."idValue", 13, 14, v.value, 16, 17)) UNION (SELECT DISTINCT t."idExtTable", t."codExtTable", t."idFieldName", t."tableDescription", f."idExtField", f."codExtField", f."fieldType", f."fieldLength", f."fieldDescription", f.nullable, f.historizable, v."idValue", NULL::text AS "strVal", NULL::numeric AS "numVal", NULL::timestamp with time zone AS "datVal", v.value AS "booVal", NULL::oid AS "lonVal" FROM "ExtTableDefinition" t, "ExtFieldDefinition" f, "ExtFieldBooleanValue" v WHERE ((t."idExtTable" = f."idExtTable") AND (f."idExtField" = v."idExtField")) ORDER BY t."idExtTable", t."codExtTable", t."idFieldName", t."tableDescription", f."idExtField", f."codExtField", f."fieldType", f."fieldLength", f."fieldDescription", f.nullable, f.historizable, v."idValue", 13, 14, 15, v.value, 17)) UNION (SELECT DISTINCT t."idExtTable", t."codExtTable", t."idFieldName", t."tableDescription", f."idExtField", f."codExtField", f."fieldType", f."fieldLength", f."fieldDescription", f.nullable, f.historizable, v."idValue", NULL::text AS "strVal", NULL::numeric AS "numVal", NULL::timestamp with time zone AS "datVal", NULL::boolean AS "booVal", v.value AS "lonVal" FROM "ExtTableDefinition" t, "ExtFieldDefinition" f, "ExtFieldLongValue" v WHERE ((t."idExtTable" = f."idExtTable") AND (f."idExtField" = v."idExtField")) ORDER BY t."idExtTable", t."codExtTable", t."idFieldName", t."tableDescription", f."idExtField", f."codExtField", f."fieldType", f."fieldLength", f."fieldDescription", f.nullable, f.historizable, v."idValue", 13, 14, 15, 16, v.value);


ALTER TABLE public."VW_EXT_ITEM_VALUES" OWNER TO "explica";

--
-- TOC entry 1298 (class 1259 OID 41583)
-- Dependencies: 1687 2
-- Name: VatType; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "VatType" (
    "idVat" numeric NOT NULL,
    description character varying(256) NOT NULL,
    "taxPercentage" numeric(5,2) NOT NULL,
    "recEquiPercentage" numeric(5,2),
    version bigint DEFAULT 0
);


ALTER TABLE public."VatType" OWNER TO "explica";

--
-- TOC entry 1337 (class 1259 OID 45004)
-- Dependencies: 2
-- Name: address_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE address_id_seq
    START WITH 1
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.address_id_seq OWNER TO "explica";

--
-- TOC entry 1341 (class 1259 OID 45012)
-- Dependencies: 2
-- Name: agent_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE agent_id_seq
    START WITH 1
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.agent_id_seq OWNER TO "explica";

--
-- TOC entry 1334 (class 1259 OID 44998)
-- Dependencies: 2
-- Name: bankaccount_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE bankaccount_id_seq
    START WITH 1
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.bankaccount_id_seq OWNER TO "explica";

--
-- TOC entry 1304 (class 1259 OID 41649)
-- Dependencies: 2
-- Name: barcodetype_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE barcodetype_id_seq
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.barcodetype_id_seq OWNER TO "explica";

--
-- TOC entry 1343 (class 1259 OID 45016)
-- Dependencies: 2
-- Name: client_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE client_id_seq
    START WITH 1
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.client_id_seq OWNER TO "explica";

--
-- TOC entry 1342 (class 1259 OID 45014)
-- Dependencies: 2
-- Name: clientgroup_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE clientgroup_id_seq
    START WITH 1
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.clientgroup_id_seq OWNER TO "explica";

--
-- TOC entry 1333 (class 1259 OID 44996)
-- Dependencies: 2
-- Name: contact_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE contact_id_seq
    START WITH 1
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.contact_id_seq OWNER TO "explica";

--
-- TOC entry 1347 (class 1259 OID 45024)
-- Dependencies: 2
-- Name: country_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE country_id_seq
    START WITH 1
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.country_id_seq OWNER TO "explica";

--
-- TOC entry 1339 (class 1259 OID 45008)
-- Dependencies: 2
-- Name: currency_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE currency_id_seq
    START WITH 1
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.currency_id_seq OWNER TO "explica";

--
-- TOC entry 1338 (class 1259 OID 45006)
-- Dependencies: 2
-- Name: department_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE department_id_seq
    START WITH 1
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.department_id_seq OWNER TO "explica";

--
-- TOC entry 1340 (class 1259 OID 45010)
-- Dependencies: 2
-- Name: discount_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE discount_id_seq
    START WITH 1
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.discount_id_seq OWNER TO "explica";

--
-- TOC entry 1293 (class 1259 OID 33387)
-- Dependencies: 2
-- Name: extfield_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE extfield_id_seq
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.extfield_id_seq OWNER TO "explica";

--
-- TOC entry 1294 (class 1259 OID 33389)
-- Dependencies: 2
-- Name: exttable_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE exttable_id_seq
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.exttable_id_seq OWNER TO "explica";

--
-- TOC entry 1349 (class 1259 OID 45028)
-- Dependencies: 2
-- Name: flag_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE flag_id_seq
    START WITH 1
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.flag_id_seq OWNER TO "explica";

--
-- TOC entry 1309 (class 1259 OID 43100)
-- Dependencies: 2
-- Name: image_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE image_id_seq
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.image_id_seq OWNER TO "explica";

--
-- TOC entry 1336 (class 1259 OID 45002)
-- Dependencies: 2
-- Name: installment_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE installment_id_seq
    START WITH 1
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.installment_id_seq OWNER TO "explica";

--
-- TOC entry 1344 (class 1259 OID 45018)
-- Dependencies: 2
-- Name: invoicingserie_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE invoicingserie_id_seq
    START WITH 1
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.invoicingserie_id_seq OWNER TO "explica";

--
-- TOC entry 1312 (class 1259 OID 43402)
-- Dependencies: 2
-- Name: measureunit_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE measureunit_id_seq
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.measureunit_id_seq OWNER TO "explica";

--
-- TOC entry 1335 (class 1259 OID 45000)
-- Dependencies: 2
-- Name: paymentmethod_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE paymentmethod_id_seq
    START WITH 1
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.paymentmethod_id_seq OWNER TO "explica";

--
-- TOC entry 1302 (class 1259 OID 41645)
-- Dependencies: 2
-- Name: product_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE product_id_seq
    START WITH 8
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.product_id_seq OWNER TO "explica";

--
-- TOC entry 1301 (class 1259 OID 41643)
-- Dependencies: 2
-- Name: productgroup_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE productgroup_id_seq
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.productgroup_id_seq OWNER TO "explica";

--
-- TOC entry 1348 (class 1259 OID 45026)
-- Dependencies: 2
-- Name: province_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE province_id_seq
    START WITH 1
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.province_id_seq OWNER TO "explica";

--
-- TOC entry 1346 (class 1259 OID 45022)
-- Dependencies: 2
-- Name: rappelinterval_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE rappelinterval_id_seq
    START WITH 1
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.rappelinterval_id_seq OWNER TO "explica";

--
-- TOC entry 1345 (class 1259 OID 45020)
-- Dependencies: 2
-- Name: rappeltype_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE rappeltype_id_seq
    START WITH 1
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.rappeltype_id_seq OWNER TO "explica";

--
-- TOC entry 1332 (class 1259 OID 44994)
-- Dependencies: 2
-- Name: rate_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE rate_id_seq
    START WITH 1
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.rate_id_seq OWNER TO "explica";

--
-- TOC entry 1303 (class 1259 OID 41647)
-- Dependencies: 2
-- Name: vattype_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE vattype_id_seq
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.vattype_id_seq OWNER TO "explica";

--
-- TOC entry 1757 (class 2606 OID 44756)
-- Dependencies: 1316 1316
-- Name: Account_pkey; Type: CONSTRAINT; Schema: public; Owner: explica; Tablespace: 
--

ALTER TABLE ONLY "BankAccount"
    ADD CONSTRAINT "Account_pkey" PRIMARY KEY ("idAccount");


--
-- TOC entry 1763 (class 2606 OID 44782)
-- Dependencies: 1319 1319
-- Name: Address_pkey; Type: CONSTRAINT; Schema: public; Owner: explica; Tablespace: 
--

ALTER TABLE ONLY "Address"
    ADD CONSTRAINT "Address_pkey" PRIMARY KEY ("idAddress");


--
-- TOC entry 1771 (class 2606 OID 44820)
-- Dependencies: 1323 1323
-- Name: Agent_pkey; Type: CONSTRAINT; Schema: public; Owner: explica; Tablespace: 
--

ALTER TABLE ONLY "Agent"
    ADD CONSTRAINT "Agent_pkey" PRIMARY KEY ("idAgent");


--
-- TOC entry 1743 (class 2606 OID 41654)
-- Dependencies: 1305 1305
-- Name: AppArea_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "AppArea"
    ADD CONSTRAINT "AppArea_pkey" PRIMARY KEY ("idArea");


--
-- TOC entry 1729 (class 2606 OID 41571)
-- Dependencies: 1296 1296
-- Name: AppResource_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "AppResource"
    ADD CONSTRAINT "AppResource_pkey" PRIMARY KEY ("idResource");


--
-- TOC entry 1741 (class 2606 OID 41637)
-- Dependencies: 1300 1300
-- Name: BarcodeType_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "BarcodeType"
    ADD CONSTRAINT "BarcodeType_pkey" PRIMARY KEY ("idBarcodeType");


--
-- TOC entry 1777 (class 2606 OID 44899)
-- Dependencies: 1326 1326 1326
-- Name: ClientAddress_pkey; Type: CONSTRAINT; Schema: public; Owner: explica; Tablespace: 
--

ALTER TABLE ONLY "ClientAddress"
    ADD CONSTRAINT "ClientAddress_pkey" PRIMARY KEY ("idClient", "idAddress");


--
-- TOC entry 1779 (class 2606 OID 44916)
-- Dependencies: 1327 1327 1327
-- Name: ClientBankAccount_pkey; Type: CONSTRAINT; Schema: public; Owner: explica; Tablespace: 
--

ALTER TABLE ONLY "ClientBankAccount"
    ADD CONSTRAINT "ClientBankAccount_pkey" PRIMARY KEY ("idClient", "idBankAccount");


--
-- TOC entry 1781 (class 2606 OID 44933)
-- Dependencies: 1328 1328 1328
-- Name: ClientContact_pkey; Type: CONSTRAINT; Schema: public; Owner: explica; Tablespace: 
--

ALTER TABLE ONLY "ClientContact"
    ADD CONSTRAINT "ClientContact_pkey" PRIMARY KEY ("idClient", "idContact");


--
-- TOC entry 1773 (class 2606 OID 44833)
-- Dependencies: 1324 1324
-- Name: ClientGroup_pkey; Type: CONSTRAINT; Schema: public; Owner: explica; Tablespace: 
--

ALTER TABLE ONLY "ClientGroup"
    ADD CONSTRAINT "ClientGroup_pkey" PRIMARY KEY ("idClientGroup");


--
-- TOC entry 1775 (class 2606 OID 44857)
-- Dependencies: 1325 1325
-- Name: Client_pkey; Type: CONSTRAINT; Schema: public; Owner: explica; Tablespace: 
--

ALTER TABLE ONLY "Client"
    ADD CONSTRAINT "Client_pkey" PRIMARY KEY ("idClient");


--
-- TOC entry 1755 (class 2606 OID 44748)
-- Dependencies: 1315 1315
-- Name: Contact_pkey; Type: CONSTRAINT; Schema: public; Owner: explica; Tablespace: 
--

ALTER TABLE ONLY "Contact"
    ADD CONSTRAINT "Contact_pkey" PRIMARY KEY ("idContact");


--
-- TOC entry 1789 (class 2606 OID 45037)
-- Dependencies: 1350 1350
-- Name: Country_pkey; Type: CONSTRAINT; Schema: public; Owner: explica; Tablespace: 
--

ALTER TABLE ONLY "Country"
    ADD CONSTRAINT "Country_pkey" PRIMARY KEY ("idCountry");


--
-- TOC entry 1767 (class 2606 OID 44798)
-- Dependencies: 1321 1321
-- Name: Currency_pkey; Type: CONSTRAINT; Schema: public; Owner: explica; Tablespace: 
--

ALTER TABLE ONLY "Currency"
    ADD CONSTRAINT "Currency_pkey" PRIMARY KEY ("idCurrency");


--
-- TOC entry 1765 (class 2606 OID 44790)
-- Dependencies: 1320 1320
-- Name: Department_pkey; Type: CONSTRAINT; Schema: public; Owner: explica; Tablespace: 
--

ALTER TABLE ONLY "Department"
    ADD CONSTRAINT "Department_pkey" PRIMARY KEY ("idDepartment");


--
-- TOC entry 1769 (class 2606 OID 44806)
-- Dependencies: 1322 1322
-- Name: Discount_pkey; Type: CONSTRAINT; Schema: public; Owner: explica; Tablespace: 
--

ALTER TABLE ONLY "Discount"
    ADD CONSTRAINT "Discount_pkey" PRIMARY KEY ("idDiscount");


--
-- TOC entry 1727 (class 2606 OID 33386)
-- Dependencies: 1292 1292 1292
-- Name: ExtFieldBooleanValue_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "ExtFieldBooleanValue"
    ADD CONSTRAINT "ExtFieldBooleanValue_pkey" PRIMARY KEY ("idExtField", "idValue");


--
-- TOC entry 1725 (class 2606 OID 33379)
-- Dependencies: 1291 1291 1291
-- Name: ExtFieldDateValue_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "ExtFieldDateValue"
    ADD CONSTRAINT "ExtFieldDateValue_pkey" PRIMARY KEY ("idExtField", "idValue");


--
-- TOC entry 1717 (class 2606 OID 33346)
-- Dependencies: 1287 1287
-- Name: ExtFieldDefinition_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "ExtFieldDefinition"
    ADD CONSTRAINT "ExtFieldDefinition_pkey" PRIMARY KEY ("idExtField");


--
-- TOC entry 1721 (class 2606 OID 33365)
-- Dependencies: 1289 1289 1289
-- Name: ExtFieldLongValue_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "ExtFieldLongValue"
    ADD CONSTRAINT "ExtFieldLongValue_pkey" PRIMARY KEY ("idExtField", "idValue");


--
-- TOC entry 1723 (class 2606 OID 33372)
-- Dependencies: 1290 1290 1290
-- Name: ExtFieldNumberValue_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "ExtFieldNumberValue"
    ADD CONSTRAINT "ExtFieldNumberValue_pkey" PRIMARY KEY ("idExtField", "idValue");


--
-- TOC entry 1719 (class 2606 OID 33358)
-- Dependencies: 1288 1288 1288
-- Name: ExtFieldStringValue_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "ExtFieldStringValue"
    ADD CONSTRAINT "ExtFieldStringValue_pkey" PRIMARY KEY ("idExtField", "idValue");


--
-- TOC entry 1715 (class 2606 OID 33339)
-- Dependencies: 1286 1286
-- Name: ExtTableDefinition_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "ExtTableDefinition"
    ADD CONSTRAINT "ExtTableDefinition_pkey" PRIMARY KEY ("idExtTable");


--
-- TOC entry 1793 (class 2606 OID 45058)
-- Dependencies: 1352 1352
-- Name: Flag_pkey; Type: CONSTRAINT; Schema: public; Owner: explica; Tablespace: 
--

ALTER TABLE ONLY "Flag"
    ADD CONSTRAINT "Flag_pkey" PRIMARY KEY ("idFlag");


--
-- TOC entry 1745 (class 2606 OID 41718)
-- Dependencies: 1307 1307
-- Name: Image_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "Image"
    ADD CONSTRAINT "Image_pkey" PRIMARY KEY ("idImage");


--
-- TOC entry 1761 (class 2606 OID 44772)
-- Dependencies: 1318 1318
-- Name: Installment_pkey; Type: CONSTRAINT; Schema: public; Owner: explica; Tablespace: 
--

ALTER TABLE ONLY "Installment"
    ADD CONSTRAINT "Installment_pkey" PRIMARY KEY ("idInstallment");


--
-- TOC entry 1783 (class 2606 OID 44983)
-- Dependencies: 1329 1329
-- Name: InvoicingSerie_pkey; Type: CONSTRAINT; Schema: public; Owner: explica; Tablespace: 
--

ALTER TABLE ONLY "InvoicingSerie"
    ADD CONSTRAINT "InvoicingSerie_pkey" PRIMARY KEY ("idSerie");


--
-- TOC entry 1749 (class 2606 OID 43401)
-- Dependencies: 1311 1311
-- Name: MeasureUnit_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "MeasureUnit"
    ADD CONSTRAINT "MeasureUnit_pkey" PRIMARY KEY ("idMeasureUnit");


--
-- TOC entry 1759 (class 2606 OID 44764)
-- Dependencies: 1317 1317
-- Name: PaymentMethod_pkey; Type: CONSTRAINT; Schema: public; Owner: explica; Tablespace: 
--

ALTER TABLE ONLY "PaymentMethod"
    ADD CONSTRAINT "PaymentMethod_pkey" PRIMARY KEY ("idPaymentMethod");


--
-- TOC entry 1731 (class 2606 OID 41582)
-- Dependencies: 1297 1297
-- Name: ProductBarcode_unique; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "Product"
    ADD CONSTRAINT "ProductBarcode_unique" UNIQUE (barcode);


--
-- TOC entry 1739 (class 2606 OID 41613)
-- Dependencies: 1299 1299
-- Name: ProductGroup_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "ProductGroup"
    ADD CONSTRAINT "ProductGroup_pkey" PRIMARY KEY ("idGroup");


--
-- TOC entry 1747 (class 2606 OID 41706)
-- Dependencies: 1308 1308 1308
-- Name: ProductImage_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "ProductImage"
    ADD CONSTRAINT "ProductImage_pkey" PRIMARY KEY ("idProduct", "idImage");


--
-- TOC entry 1753 (class 2606 OID 44707)
-- Dependencies: 1314 1314 1314
-- Name: ProductMeasureUnit_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "ProductMeasureUnit"
    ADD CONSTRAINT "ProductMeasureUnit_pkey" PRIMARY KEY ("idProduct", "idMeasureUnit");


--
-- TOC entry 1733 (class 2606 OID 41580)
-- Dependencies: 1297 1297
-- Name: ProductReference_unique; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "Product"
    ADD CONSTRAINT "ProductReference_unique" UNIQUE (reference);


--
-- TOC entry 1735 (class 2606 OID 41578)
-- Dependencies: 1297 1297
-- Name: Product_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "Product"
    ADD CONSTRAINT "Product_pkey" PRIMARY KEY ("idProduct");


--
-- TOC entry 1791 (class 2606 OID 45045)
-- Dependencies: 1351 1351
-- Name: Province_pkey; Type: CONSTRAINT; Schema: public; Owner: explica; Tablespace: 
--

ALTER TABLE ONLY "Province"
    ADD CONSTRAINT "Province_pkey" PRIMARY KEY ("idProvince");


--
-- TOC entry 1787 (class 2606 OID 44981)
-- Dependencies: 1331 1331
-- Name: RappelInterval_pkey; Type: CONSTRAINT; Schema: public; Owner: explica; Tablespace: 
--

ALTER TABLE ONLY "RappelInterval"
    ADD CONSTRAINT "RappelInterval_pkey" PRIMARY KEY ("idRappelInterval");


--
-- TOC entry 1785 (class 2606 OID 44973)
-- Dependencies: 1330 1330
-- Name: RappelType_pkey; Type: CONSTRAINT; Schema: public; Owner: explica; Tablespace: 
--

ALTER TABLE ONLY "RappelType"
    ADD CONSTRAINT "RappelType_pkey" PRIMARY KEY ("idRappel");


--
-- TOC entry 1751 (class 2606 OID 44510)
-- Dependencies: 1313 1313
-- Name: Rate_pkey; Type: CONSTRAINT; Schema: public; Owner: explica; Tablespace: 
--

ALTER TABLE ONLY "Rate"
    ADD CONSTRAINT "Rate_pkey" PRIMARY KEY ("idRate");


--
-- TOC entry 1737 (class 2606 OID 41600)
-- Dependencies: 1298 1298
-- Name: VatType_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "VatType"
    ADD CONSTRAINT "VatType_pkey" PRIMARY KEY ("idVat");


--
-- TOC entry 1806 (class 2606 OID 45074)
-- Dependencies: 1319 1350 1788
-- Name: Address_idCountry_fkey; Type: FK CONSTRAINT; Schema: public; Owner: explica
--

ALTER TABLE ONLY "Address"
    ADD CONSTRAINT "Address_idCountry_fkey" FOREIGN KEY ("idCountry") REFERENCES "Country"("idCountry");


--
-- TOC entry 1807 (class 2606 OID 45079)
-- Dependencies: 1319 1351 1790
-- Name: Address_idProvince_fkey; Type: FK CONSTRAINT; Schema: public; Owner: explica
--

ALTER TABLE ONLY "Address"
    ADD CONSTRAINT "Address_idProvince_fkey" FOREIGN KEY ("idProvince") REFERENCES "Province"("idProvince");


--
-- TOC entry 1810 (class 2606 OID 44834)
-- Dependencies: 1323 1319 1762
-- Name: Agent_idAdress_fkey; Type: FK CONSTRAINT; Schema: public; Owner: explica
--

ALTER TABLE ONLY "Agent"
    ADD CONSTRAINT "Agent_idAdress_fkey" FOREIGN KEY ("idAddress") REFERENCES "Address"("idAddress");


--
-- TOC entry 1809 (class 2606 OID 44821)
-- Dependencies: 1323 1320 1764
-- Name: Agent_idDepartment_fkey; Type: FK CONSTRAINT; Schema: public; Owner: explica
--

ALTER TABLE ONLY "Agent"
    ADD CONSTRAINT "Agent_idDepartment_fkey" FOREIGN KEY ("idDepartment") REFERENCES "Department"("idDepartment");


--
-- TOC entry 1795 (class 2606 OID 41655)
-- Dependencies: 1296 1305 1742
-- Name: AppResourceAppArea_fkey; Type: FK CONSTRAINT; Schema: public; Owner: admin
--

ALTER TABLE ONLY "AppResource"
    ADD CONSTRAINT "AppResourceAppArea_fkey" FOREIGN KEY ("idArea") REFERENCES "AppArea"("idArea");


--
-- TOC entry 1819 (class 2606 OID 44905)
-- Dependencies: 1326 1319 1762
-- Name: ClientAddress_idAddress_fkey; Type: FK CONSTRAINT; Schema: public; Owner: explica
--

ALTER TABLE ONLY "ClientAddress"
    ADD CONSTRAINT "ClientAddress_idAddress_fkey" FOREIGN KEY ("idAddress") REFERENCES "Address"("idAddress");


--
-- TOC entry 1818 (class 2606 OID 44900)
-- Dependencies: 1326 1325 1774
-- Name: ClientAddress_idClient_fkey; Type: FK CONSTRAINT; Schema: public; Owner: explica
--

ALTER TABLE ONLY "ClientAddress"
    ADD CONSTRAINT "ClientAddress_idClient_fkey" FOREIGN KEY ("idClient") REFERENCES "Client"("idClient");


--
-- TOC entry 1821 (class 2606 OID 44922)
-- Dependencies: 1327 1316 1756
-- Name: ClientBankAccount_idBankAccount_fkey; Type: FK CONSTRAINT; Schema: public; Owner: explica
--

ALTER TABLE ONLY "ClientBankAccount"
    ADD CONSTRAINT "ClientBankAccount_idBankAccount_fkey" FOREIGN KEY ("idBankAccount") REFERENCES "BankAccount"("idAccount");


--
-- TOC entry 1820 (class 2606 OID 44917)
-- Dependencies: 1327 1325 1774
-- Name: ClientBankAccount_idClient_fkey; Type: FK CONSTRAINT; Schema: public; Owner: explica
--

ALTER TABLE ONLY "ClientBankAccount"
    ADD CONSTRAINT "ClientBankAccount_idClient_fkey" FOREIGN KEY ("idClient") REFERENCES "Client"("idClient");


--
-- TOC entry 1822 (class 2606 OID 44934)
-- Dependencies: 1328 1325 1774
-- Name: ClientContact_idClient_fkey; Type: FK CONSTRAINT; Schema: public; Owner: explica
--

ALTER TABLE ONLY "ClientContact"
    ADD CONSTRAINT "ClientContact_idClient_fkey" FOREIGN KEY ("idClient") REFERENCES "Client"("idClient");


--
-- TOC entry 1823 (class 2606 OID 44939)
-- Dependencies: 1328 1315 1754
-- Name: ClientContact_idContact_fkey; Type: FK CONSTRAINT; Schema: public; Owner: explica
--

ALTER TABLE ONLY "ClientContact"
    ADD CONSTRAINT "ClientContact_idContact_fkey" FOREIGN KEY ("idContact") REFERENCES "Contact"("idContact");


--
-- TOC entry 1811 (class 2606 OID 44878)
-- Dependencies: 1324 1313 1750
-- Name: ClientGroup_idRate_fkey; Type: FK CONSTRAINT; Schema: public; Owner: explica
--

ALTER TABLE ONLY "ClientGroup"
    ADD CONSTRAINT "ClientGroup_idRate_fkey" FOREIGN KEY ("idRate") REFERENCES "Rate"("idRate");


--
-- TOC entry 1813 (class 2606 OID 44863)
-- Dependencies: 1325 1323 1770
-- Name: Client_idAgent_fkey; Type: FK CONSTRAINT; Schema: public; Owner: explica
--

ALTER TABLE ONLY "Client"
    ADD CONSTRAINT "Client_idAgent_fkey" FOREIGN KEY ("idAgent") REFERENCES "Agent"("idAgent");


--
-- TOC entry 1812 (class 2606 OID 44858)
-- Dependencies: 1325 1324 1772
-- Name: Client_idClientGroup_fkey; Type: FK CONSTRAINT; Schema: public; Owner: explica
--

ALTER TABLE ONLY "Client"
    ADD CONSTRAINT "Client_idClientGroup_fkey" FOREIGN KEY ("idClientGroup") REFERENCES "ClientGroup"("idClientGroup");


--
-- TOC entry 1815 (class 2606 OID 44873)
-- Dependencies: 1325 1321 1766
-- Name: Client_idCurrency_fkey; Type: FK CONSTRAINT; Schema: public; Owner: explica
--

ALTER TABLE ONLY "Client"
    ADD CONSTRAINT "Client_idCurrency_fkey" FOREIGN KEY ("idCurrency") REFERENCES "Currency"("idCurrency");


--
-- TOC entry 1816 (class 2606 OID 44984)
-- Dependencies: 1325 1329 1782
-- Name: Client_idInvoicingSerie_fkey; Type: FK CONSTRAINT; Schema: public; Owner: explica
--

ALTER TABLE ONLY "Client"
    ADD CONSTRAINT "Client_idInvoicingSerie_fkey" FOREIGN KEY ("idInvoicingSerie") REFERENCES "InvoicingSerie"("idSerie");


--
-- TOC entry 1814 (class 2606 OID 44868)
-- Dependencies: 1325 1317 1758
-- Name: Client_idPaymentMethod_fkey; Type: FK CONSTRAINT; Schema: public; Owner: explica
--

ALTER TABLE ONLY "Client"
    ADD CONSTRAINT "Client_idPaymentMethod_fkey" FOREIGN KEY ("idPaymentMethod") REFERENCES "PaymentMethod"("idPaymentMethod");


--
-- TOC entry 1817 (class 2606 OID 44989)
-- Dependencies: 1325 1330 1784
-- Name: Client_idRappelType_fkey; Type: FK CONSTRAINT; Schema: public; Owner: explica
--

ALTER TABLE ONLY "Client"
    ADD CONSTRAINT "Client_idRappelType_fkey" FOREIGN KEY ("idRappelType") REFERENCES "RappelType"("idRappel");


--
-- TOC entry 1824 (class 2606 OID 45069)
-- Dependencies: 1350 1352 1792
-- Name: Country_idFlag_fkey; Type: FK CONSTRAINT; Schema: public; Owner: explica
--

ALTER TABLE ONLY "Country"
    ADD CONSTRAINT "Country_idFlag_fkey" FOREIGN KEY ("idFlag") REFERENCES "Flag"("idFlag");


--
-- TOC entry 1808 (class 2606 OID 45064)
-- Dependencies: 1321 1352 1792
-- Name: Currency_idFlag_fkey; Type: FK CONSTRAINT; Schema: public; Owner: explica
--

ALTER TABLE ONLY "Currency"
    ADD CONSTRAINT "Currency_idFlag_fkey" FOREIGN KEY ("idFlag") REFERENCES "Flag"("idFlag");


--
-- TOC entry 1794 (class 2606 OID 33347)
-- Dependencies: 1287 1286 1714
-- Name: ExtFieldDefinition_idExtTable_fkey; Type: FK CONSTRAINT; Schema: public; Owner: admin
--

ALTER TABLE ONLY "ExtFieldDefinition"
    ADD CONSTRAINT "ExtFieldDefinition_idExtTable_fkey" FOREIGN KEY ("idExtTable") REFERENCES "ExtTableDefinition"("idExtTable");


--
-- TOC entry 1826 (class 2606 OID 45059)
-- Dependencies: 1352 1296 1728
-- Name: Flag_idResource_fkey; Type: FK CONSTRAINT; Schema: public; Owner: explica
--

ALTER TABLE ONLY "Flag"
    ADD CONSTRAINT "Flag_idResource_fkey" FOREIGN KEY ("idResource") REFERENCES "AppResource"("idResource");


--
-- TOC entry 1805 (class 2606 OID 44839)
-- Dependencies: 1318 1317 1758
-- Name: Installment_idPaymentMethod_fkey; Type: FK CONSTRAINT; Schema: public; Owner: explica
--

ALTER TABLE ONLY "Installment"
    ADD CONSTRAINT "Installment_idPaymentMethod_fkey" FOREIGN KEY ("idPaymentMethod") REFERENCES "PaymentMethod"("idPaymentMethod");


--
-- TOC entry 1804 (class 2606 OID 44844)
-- Dependencies: 1317 1316 1756
-- Name: PaymentMethod_idBankAccount_fkey; Type: FK CONSTRAINT; Schema: public; Owner: explica
--

ALTER TABLE ONLY "PaymentMethod"
    ADD CONSTRAINT "PaymentMethod_idBankAccount_fkey" FOREIGN KEY ("idBankAccount") REFERENCES "BankAccount"("idAccount");


--
-- TOC entry 1799 (class 2606 OID 43302)
-- Dependencies: 1299 1286 1714
-- Name: ProductGroup_idExtTable_fkey; Type: FK CONSTRAINT; Schema: public; Owner: admin
--

ALTER TABLE ONLY "ProductGroup"
    ADD CONSTRAINT "ProductGroup_idExtTable_fkey" FOREIGN KEY ("idExtTable") REFERENCES "ExtTableDefinition"("idExtTable");


--
-- TOC entry 1801 (class 2606 OID 41724)
-- Dependencies: 1308 1307 1744
-- Name: ProductImage_idImage_fkey; Type: FK CONSTRAINT; Schema: public; Owner: admin
--

ALTER TABLE ONLY "ProductImage"
    ADD CONSTRAINT "ProductImage_idImage_fkey" FOREIGN KEY ("idImage") REFERENCES "Image"("idImage");


--
-- TOC entry 1800 (class 2606 OID 41707)
-- Dependencies: 1308 1297 1734
-- Name: ProductImage_idProduct_fkey; Type: FK CONSTRAINT; Schema: public; Owner: admin
--

ALTER TABLE ONLY "ProductImage"
    ADD CONSTRAINT "ProductImage_idProduct_fkey" FOREIGN KEY ("idProduct") REFERENCES "Product"("idProduct");


--
-- TOC entry 1802 (class 2606 OID 44708)
-- Dependencies: 1314 1311 1748
-- Name: ProductMeasureUnit_idMeasureUnit_fkey; Type: FK CONSTRAINT; Schema: public; Owner: admin
--

ALTER TABLE ONLY "ProductMeasureUnit"
    ADD CONSTRAINT "ProductMeasureUnit_idMeasureUnit_fkey" FOREIGN KEY ("idMeasureUnit") REFERENCES "MeasureUnit"("idMeasureUnit");


--
-- TOC entry 1803 (class 2606 OID 44713)
-- Dependencies: 1314 1297 1734
-- Name: ProductMeasureUnit_idProduct_fkey; Type: FK CONSTRAINT; Schema: public; Owner: admin
--

ALTER TABLE ONLY "ProductMeasureUnit"
    ADD CONSTRAINT "ProductMeasureUnit_idProduct_fkey" FOREIGN KEY ("idProduct") REFERENCES "Product"("idProduct");


--
-- TOC entry 1798 (class 2606 OID 41638)
-- Dependencies: 1297 1300 1740
-- Name: Product_idBarcodeType_fkey; Type: FK CONSTRAINT; Schema: public; Owner: admin
--

ALTER TABLE ONLY "Product"
    ADD CONSTRAINT "Product_idBarcodeType_fkey" FOREIGN KEY ("idBarcodeType") REFERENCES "BarcodeType"("idBarcodeType");


--
-- TOC entry 1797 (class 2606 OID 41614)
-- Dependencies: 1297 1299 1738
-- Name: Product_idGroup_fkey; Type: FK CONSTRAINT; Schema: public; Owner: admin
--

ALTER TABLE ONLY "Product"
    ADD CONSTRAINT "Product_idGroup_fkey" FOREIGN KEY ("idGroup") REFERENCES "ProductGroup"("idGroup");


--
-- TOC entry 1796 (class 2606 OID 41601)
-- Dependencies: 1297 1298 1736
-- Name: Product_idVat_fkey; Type: FK CONSTRAINT; Schema: public; Owner: admin
--

ALTER TABLE ONLY "Product"
    ADD CONSTRAINT "Product_idVat_fkey" FOREIGN KEY ("idVat") REFERENCES "VatType"("idVat");


--
-- TOC entry 1825 (class 2606 OID 45046)
-- Dependencies: 1351 1350 1788
-- Name: Province_idCountry_fkey; Type: FK CONSTRAINT; Schema: public; Owner: explica
--

ALTER TABLE ONLY "Province"
    ADD CONSTRAINT "Province_idCountry_fkey" FOREIGN KEY ("idCountry") REFERENCES "Country"("idCountry");


--
-- TOC entry 1830 (class 0 OID 0)
-- Dependencies: 2
-- Name: public; Type: ACL; Schema: -; Owner: explica
--

REVOKE ALL ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON SCHEMA public FROM explica;
GRANT ALL ON SCHEMA public TO explica;
GRANT ALL ON SCHEMA public TO PUBLIC;


-- Completed on 2009-03-03 11:45:17 CET

--
-- PostgreSQL database dump complete
--

